<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/taglib_include.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, target-densitydpi=medium-dpi, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<link href="${ctx}/css/main.css?ver=${main_css_version}" rel="stylesheet" type="text/css" />
<title>${projectTitle }</title>
</head>
<body>
   <header id="main-top">
    <a href="${ctx}/resetpwd/index.do">
      <div id="main-top-left">
        <img src="${ctx}/images/mui_title_back_btn.png" class="img-2">
      </div>
    </a>
    <div id="main-top-title">重置密码</div>

  </header>
    <div id="container">
    <div id="login">
      <ul>
        <li style="color: #1b488b;">已向手机${mobile}发送验证码</li>
        <li><label>验证码</label><input class="loginInput" type="text" name="captcha" id="captcha" placeholder="请输入验证码" /></li>
      </ul>
      <input type="hidden" name="username" value="${username}" id="username"/>
      <div id="tip-r">提交后，您的密码将重置为手机号后6位</div>
    </div>
  </div>
  <div id="big-button">
    <a href="javascript:void(0);" id="resetpwdBtn">
      <div id="determine">提交</div>
    </a>
  </div>

<style type="text/css">
/*弹出层的STYLE*/
.popdiv {
    background-color: white;
    text-align: center;
    line-height: 40px;
    z-index:99;
    width: 80%;
    position:fixed!important;
}

#divbg {
    background-color: #ccc;
    width: 100%;
    height: 100%;
    left:0;
    top:0;
    filter:alpha(opacity=50);
    opacity:0.5;
    z-index:1;
    position:fixed!important;
}
/*The END*/
</style>
  <!-- 重置密码弹出层 -->
  <div id="Layer-thickness" style="display:none;width: 80%;" class="popdiv">
    <div id="Layer-thickness-concent"></div>
    <div class="tips3-button">
      <a href="javascript:void(0);" id="confirmBtn">确定</a>
    </div>
  </div>
  <!-- 弹出层背景 -->
  <div id="divbg" style="display: none;">
  </div>
  <script type="text/javascript" src="${ctx}/js/jquery.min.js?ver=${jquery_min_version}"></script>
  <script type="text/javascript">
  var resetpwdResult = false; // 重置密码结果,true:成功, false:失败
  var SUCC = ${SUCCESS}; // 重置密码成功编码
  var INVALID = ${CAPTCHA_INVALID};// 验证码无效编码
  
  $(function(){
	  // 提交按钮事件绑定
	  $("#determine").bind("click", function(){
		  resetpwd();
	  });
	  // 弹出层事件绑定
	  $("#confirmBtn").bind("click", function(){
		  if (resetpwdResult) {
			  WeixinJSBridge.call('closeWindow');
		  } else {
			  closePopDiv();
		  }
	  });
  });
  /* 重置密码 */
  function resetpwd(){
      var c = $("#captcha").val();
      var u = $("#username").val();
      $.ajax({
          type: "POST",
          url:"${ctx}/resetpwd/resetpassword.do",
          data:{captcha:c, username:u},
          success:function (data){         
              if(data.errcode == SUCC){
            	  resetpwdResult = true;
            	  openPopDiv("找回密码成功，您的密码已经被重置为手机号后6位。");
              } else if (data.errcode == INVALID) {
            	  resetpwdResult = false;
            	  openPopDiv(data.errmsg + ", 请返回找回密码页面重新发送验证码 ");
              } else {
                  resetpwdResult = false;
                  openPopDiv(data.errmsg);
              }
          }
      });
  }
  /* 跳转到登录页面 */
  function gotoLogin(){
	  closePopDiv();
	  window.location.href = "${ctx}/login/index.do";
  }
  /* 打开弹出层消息提示 */
  function openPopDiv(msg) {
	  var popDiv = $(".popdiv");
	  var popContent = $("#Layer-thickness-concent");
	  popDiv.css({display:"block"});
      document.getElementById("divbg").style.display = "block";
      //获取弹出窗口的长度和宽度
      var showdivwidth = popDiv.width();
      var showdivheight = popDiv.height();
      var iTop=($(window).height()-showdivheight)/2; 
      var iLeft=($(window).width()-showdivwidth)/2; 
      popDiv.css({left:iLeft,top:iTop});
      
      popContent.text(msg);
  }
  /* 关闭弹出层 */
  function closePopDiv(){
	  $(".popdiv").css({display:"none"});
	  document.getElementById('divbg').style.display='none';
  }
  </script>
</body>
</html>